<?php
$manageStr = $messageId > 0 ? Yii::t('site','View Message') : Yii::t('site','Send Message');
$sendToStr = Yii::t('site','Send To');
$messageBodyStr = Yii::t('site','Message Body');
$addBasicInfoStr = Yii::t('site','Add basic info');

$screen = Blyn::app()->getCurrentNode()->getUIManager()->getCurrentScreen();

$messageModel = new MessageFormModel();
?>

<script type="text/javascript">
$('body').on('hidden.bs.modal', '.modal', function () {
    $(this).removeData('bs.modal');
});
</script>

<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
    <h3><?php echo $manageStr; ?></h3>
</div>
<div class="modal-body">

    <div class="tabbable tabs-right" style="margin-top: 15px;"> <!-- Only required for left/right tabs -->
        <ul class="nav nav-tabs" style="margin-bottom: 15px">
            <li class="active"><a href="#tab1" data-toggle="tab"><?php echo $addBasicInfoStr; ?></a></li>
        </ul>
        <div class="tab-content">
            <div class="tab-pane active" id="tab1" style="min-height: 270px">
                <div class="well">
                    <?php if ($messageId == 0) { ?>
                    <label><?php echo $sendToStr; ?>:</label>
                    <?php echo CHtml::activeTextField($messageModel, 'sendTo', array('value'=>'', 'name' => "sendTo", 'placeholder' => 'Type name...', 'required' => true)); ?>                
                    <label><?php echo $messageBodyStr; ?>:</label>                
                    <?php echo CHtml::activeTextArea($messageModel, 'messageBody', array('name' => "messageBody", 'placeholder' => 'Type Message...')); ?>
                    <?php } else {
                        $medias = $message->getMediaManager()->getMedias();
                        foreach ($medias as $media) {
                    ?>
                    <label><?php echo $messageBodyStr; ?>:</label>
                    <?php echo CHtml::encode($media->getContent()); ?>
                    <?php } } ?>
                </div>
            </div>
        </div>
    </div>

</div>     
<div class="modal-footer">
    <button class="btn" data-dismiss="modal" aria-hidden="true"><?php echo Yii::t('site','Close'); ?></button>
<?php
if ($messageId == 0) {
    echo $screen->getAjaxLink(array('name'=>Yii::t('site','Send Message'), 'id'=>'sendMessage'),
        array('ajaxContainerId' => 'messageDialog',
        'htmlOptions' => array('class' => 'btn btn-primary'),
        'ajaxOptions' => array('complete' => 'function(){$("#ajax-loaderdiv").hide();$("#messageDialog").modal("hide");$("#refreshIt").click();}')));
}
?>
</div>
